package messenger;

import java.awt.event.*;
import javax.swing.*;

public class ConnectionWindow {
    
    private JFrame frame;
    private JLabel label;
    private JTextField field;
    private JPanel panel;
        
    public ConnectionWindow() {
        this.go();
    }

    private void go() {
        frame = new JFrame("Tela de conexao");
        
        label = new JLabel("entre com o ip: ");
        
        field = new JTextField(12);
        field.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                new GenericClient(field.getText(), 5000); 
            }
        });
        
        JButton button = new JButton("conectar");
        button.addActionListener(new ConectorActionListener());
        
        panel = new JPanel();        
        panel.add(label);
        panel.add(field);
        panel.add(button);
        frame.setContentPane(panel);        
          
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.pack();
        frame.setResizable(false);
        frame.setIconImage(new ImageIcon("imagens\\messenger.jpg").getImage());        
        frame.setVisible(true);
    }  
         
    public class ConectorActionListener implements ActionListener{

        public void actionPerformed(ActionEvent e) {
            new GenericClient(field.getText(), 5000);
        }    
    }    
}
